

/**
 * Description:
 * 网站: <a href="http://www.crazyit.org">疯狂Java联盟</a><br>
 * Copyright (C), 2001-2016, Yeeku.H.Lee<br>
 * This program is protected by copyright laws.<br>
 * Program Name: <br>
 * Date: <br>
 * @author Yeeku.H.Lee kongyeeku@163.com
 * @version 1.0
 */
public class 强制转换
{
	public static void main(String[] args)
	{
		double db = 34.99999;

		// db是double，double不能自动转换int
		// 此时，就需要进行强转
		int it = (int)db;

		System.out.println(it);

		int it2 = 66;

		// it2是int型，int不能自动转换char，需要强转
		char c = (char)it2;
		System.out.println(c);

		int i = 2;
		char c2 = (char)(i * 10 + 65);
		System.out.println(c2);


		// -----------下面示范溢出----------

		int it3 = 600;

		// byte取值范围是-128~127, 200就会溢出
        //溢出规则：用该数-目标类型大小*n
		byte bt = (byte)it3;  // byte总范围是256 600-256=>344-256=>88
		System.out.println(bt);

		int it4 = 40000;
		short st = (short)it4;  // short总范围是65536 40000-65536=>-25536
		System.out.println(st);

	}
}
